<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box{
            width: 150px;
            height: 150px;
            border: 1px solid red;
            font-size: 50px;
            text-align: center;
            line-height: 150px;
            float: left;
            margin: 8px;
        }
        .body{
            height: 3000px;
        }
    
    
    </style>
</head>
<body>
    <h1>网页中一共有<span>n</span>个盒子</h1>
    <script src="js/jquery-3.3.1.min.js"></script>
    <script>
        $ (function () {
            // alert("jquery ok!")
            $("body").click(function(){
                var n=$(".box").length+1;
                var str="<div class='box'>"+n+"</div>";
                $("body").append(str);//在body的内部最后面加一个盒子
                $("span").text(n)
            });
        });
    </script>

</body>
</html>